package com.lession.controller;

import com.lession.Dto.GetLessonsReqDto;
import com.lession.common.LessionException;
import com.lession.common.Ret;
import com.lession.common.RetEnum;
import com.lession.service.LessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/lesson")
public class LessonController {
	
	@Autowired
	private LessonService lessonService;
	
	@RequestMapping(value = "/page/get", method = RequestMethod.POST)
	public Ret getLessonsByStu(@RequestBody GetLessonsReqDto dto) {
		try {
			return Ret.ok().data(lessonService.getLessonsByStu(dto)).build();
		} catch (LessionException e) {
			return Ret.error(e.getCode()).msg(e.getMessage()).build();
		} catch (Exception e) {
			return Ret.error(RetEnum.INTERFACE_CALL_FAIL_ERROR.getCode()).build();
		}
	}
	
	@RequestMapping(value = "/courses/get", method = RequestMethod.POST)
	public Ret getCourses() {
		try {
			return Ret.ok().data(lessonService.selectCourses()).build();
		} catch (LessionException e) {
			return Ret.error(e.getCode()).msg(e.getMessage()).build();
		} catch (Exception e) {
			return Ret.error(RetEnum.INTERFACE_CALL_FAIL_ERROR.getCode()).build();
		}
	}
	
	@RequestMapping(value = "/byday/get", method = RequestMethod.POST)
	public Ret getlessonByday(@RequestBody GetLessonsReqDto dto) {
		try {
			return Ret.ok().data(lessonService.getlessonByday(dto)).build();
		} catch (LessionException e) {
			return Ret.error(e.getCode()).msg(e.getMessage()).build();
		} catch (Exception e) {
			return Ret.error(RetEnum.INTERFACE_CALL_FAIL_ERROR.getCode()).build();
		}
	}
}
